<template>
	<view class="page index">
		<view class="form">
			<common-input
			  title="回款客户" 
				placeholder="请选择" 
				v-model="detail.customerName"
				:border-bottom="false"
				:disabled="true"
			>
			</common-input>
			<common-input
			  title="所属合同" 
				placeholder="请选择" 
				v-model="detail.contract.name"
				:border-bottom="false"
				:disabled="true"
			>
			</common-input>
			<common-input
			  title="回款金额" 
				placeholder="请填写回款金额(人民币/元)" 
				v-model="detail.price"
				:border-bottom="false"
			>
			</common-input>
			<picker mode="date" @change="selectSignTime">
				<view class="picker">
					<common-input
					  title="回款日期" 
						placeholder="请填写回款日期" 
						v-model="time"
						:border-bottom="false"
					>
					</common-input>
				</view>
			</picker>
			<picker mode="selector" :value="typeIndex" :range="typeList" @change="changeType">
				<view class="picker">
					<common-input
					  title="回款方式" 
						placeholder="请选择回款方式" 
						v-model="typeIndex < 0 ? '' : typeList[typeIndex]"
						:disabled="true"
						:require="false"
						:select="true"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						备注
					</view>
					<!-- <view class="require"></view> -->
				</view>
				<textarea v-model="detail.remark" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<update-file :require="true" title="回款凭证" @update="updatefiles" :paths="paths"></update-file>
		</view>
		<view class="footer">
			<!-- <button class="cancel">保存为草稿</button> -->
			<button class="confire" @click="save">提交审批</button>
		</view>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import updateFile from "@/components/updateFile.vue";
	import {updatePaymentApi} from "@/api/paymentCollection_api.js";
	export default{
		data() {
			return{
				time:'',
				typeIndex: 0,
				typeList:['支票', '现金', '邮政汇款', '电汇', '网上转账', '支付宝', '微信支付', '其他'],
				fileUrls: [],
				paths: [],
				detail: {}
			}
		},
		components: {
			commonInput,
			updateFile
		},
		onLoad(e) {
			this.detail = JSON.parse(e.detail);
			this.time = this.$share.getDate(this.detail.returnTime);
			this.typeIndex = this.detail.returnType - 1;
			this.fileUrls = this.detail.fileUrls;
			for(let i = 0; i < this.detail.fileUrls.length; i++){
				this.paths.push({path:this.detail.fileUrls[i], name: i+1})
			}
		},
		methods:{
			// 选择回款日期
			selectSignTime(e){
				this.time = e.detail.value
			},
			changeType(e){
				this.typeIndex = e.detail.value
			},
			updatefiles(e){
				this.fileUrls = e.map(item => item.path);
			},
			save(){
				if(this.detail.price == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写回款金额'
					})
					return;
				}
				if(this.time == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写回款日期'
					})
					return;
				}
				if(this.fileUrls.length == 0){
					uni.showToast({
						icon: 'none',
						title: '请上传回款凭证'
					})
					return;
				}
				uni.showLoading({
					mask:true,
					title:'加载中...'
				})
				updatePaymentApi({
					id: this.detail.id,
					customerId: this.detail.customerId,
					contractId: this.detail.contractId,
					returnType: Number(this.typeIndex) + 1,
					price: this.detail.price,
					returnTime: new Date(this.time).getTime(),
					remark: this.detail.remark,
					fileUrls: this.fileUrls
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
							icon: 'success',
							title: '编辑成功'
						})
						setTimeout(() => {
							uni.navigateBack();
						},1500)
					}).catch(() => {
						uni.hideLoading();
					})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 30rpx;
			@include flex-r-center-start;
			button{
				@include button;
				color: #fff;
				height: 60rpx;
				width: 80%;
				line-height: 60rpx;
				font-size: 28rpx;
			}
			.cancel{
				background-color: #bebebe;
			}
			.confire{
				background-color: #198AFA;
			}
		}
	}
</style>